var request = require('../../utils/request.js')
Page({
  data: {
    lists: [],
    total: 1,
    height: '',
    lng: '',
    lat: '',
    pagenumber: 1
  },
  enter: function (e) {
    my.navigateTo({
      url: 'order?sn=' + e.currentTarget.dataset.sn
    })
  },
  getData: function () {
    if (this.data.pagenumber <= this.data.total) {
      var that = this
      var success = function (data) {
        if (that.data.pagenumber > parseInt(data["pagesum"])) {
          that.data.lists = []
        }
        that.data.lists = that.data.lists.concat(data["res"])
        that.setData({
          lists: that.data.lists
        })
        that.data.total = parseInt(data["pagesum"]);
        that.data.pagenumber++;
      }
      request.postdata('/Map/getFacilityList', {
        "pagination": that.data.pagenumber,
        // 'lng': that.data.lng,
        // 'lat': that.data.lat,
        'lng': '104.04604',
        'lat': '30.52533',
        'skey': that.data.skey
      }, success, that)
    }
  },
  onLoad: function (data) {
    var that = this
    my.getSystemInfo({
      success: function (res) {
        that.setData({
          height: (res.windowHeight - 43) + 'px'
        })
      }
    })
    this.data.lng = data['lng']
    this.data.lat = data['lat']
    this.setData({
        skey: data['skey']
    })
    this.getData()
  },
  onShow(){
    my.getNetworkType({
      success: (res) => {
        if(!res.networkAvailable||res.networkType=='UNKNOWN'){
          my.showToast({
            content: '网络状态不佳，请检查网络',
            type:'fail',
            duration: 2000
          })
        }
      }
    })
  },
  input: function (e) {
    this.data.skey = e.detail.value
    this.data.pagenumber = 1
    this.data.total = 1
    this.data.lists = []
    this.getData()
  },
  refresh: function (e) {
    this.data.pagenumber = 1
    this.data.total = 1
    this.data.lists = []
    this.getData()
  },
  more: function (e) {
    this.getData()
  }
})